// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// y [author] rhyme_lph
// E [email]  rhymelph@gmail.com
// e [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';
import 'package:finance_app/src/widgets/bottom_sheet/category_bottom_sheet.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/src/provider/dashboard/select/select_category_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';

@RouterMeta(paramName: "selectCategoryPage")
class SelectCategoryPage extends StatefulWidget {
  final SettingDataCategory select;
  final SettingDataCurrency unit;
  final bool isPop;
  final String type; //expense
  const SelectCategoryPage(
      {Key key, this.select, this.unit, this.isPop, this.type})
      : super(key: key);

  @override
  _SelectCategoryPageState createState() => _SelectCategoryPageState();
}

class _SelectCategoryPageState extends State<SelectCategoryPage>
    with PagePresenter<SelectCategoryPage, SelectCategoryProvider> {
  @override
  void initState() {
    provider.type = widget.type;
    provider.unit = widget.unit;
    provider.currentSelectCode = widget.select;
    if (widget.isPop != null) {
      provider.isPop = widget.isPop;
    }
    super.initState();
  }

  @override
  PreferredSizeWidget get appBar => getDefaultAppBar(
        title: S.current.select_category,
      );

  @override
  Widget get buildEmptyWidget => ColoredBox(
        color: Colors.white,
        child: CategoryWidget(
          isSinglePage: true,
          categories: provider.data,
          recentIds: provider.recentIds,
          currentSelectCode: provider.currentSelectCode,
          selectCallBack: provider.onChangeSelect,
        ),
      );

  @override
  Widget get buildWidget => ColoredBox(
        color: Colors.white,
        child: CategoryWidget(
          isSinglePage: true,
          categories: provider.data,
          recentIds: provider.recentIds,
          currentSelectCode: provider.currentSelectCode,
          selectCallBack: provider.onChangeSelect,
        ),
      );
}
